﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AutoMapper;
using Tools.Domain.Common.Repositories.Contracts;
using Webshop20.Domain.Customers.Core;
using Webshop20.Domain.Customers.Services.Contracts;


namespace Webshop20.Domain.Customers.Services.DataTransferObjects
{
    public class CustomerInformationService : ICustomerInformationService
    {
        private IRepository<Customer> customerRepository;

        public CustomerInformationService(IRepository<Customer> customerRepository)
        {
            this.customerRepository = customerRepository;
        }

        public CustomerInformationDTO GetCustomerById(int id)
        {
            var customer = customerRepository.FindById(id);
            return Mapper.Map<Customer, CustomerInformationDTO>(customer);
        }

        public IEnumerable<CustomerInformationDTO> GetCustomersById(IEnumerable<int> customerIds)
        {
            return customerRepository
                    .Find(customer => customerIds.Contains(customer.Id))
                    .Distinct()
                    .Select(customer=>new CustomerInformationDTO(
                                                                    customer.Id, 
                                                                    customer.FirstName, 
                                                                    customer.LastName, 
                                                                    customer.Adress.Street, 
                                                                    customer.Adress.PostalCode, 
                                                                    customer.Adress.City, 
                                                                    customer.Adress.Country, 
                                                                    customer.EMail));
        }
    }
}
